<template>
<div class="column">
    <div class="swarchBox">
        <img src="https://youyang-cdn.mdshuzhi.com/upload/icon_search@2x.png" />
        <input placeholder="搜索关键词找栏目" v-model="search" confirm-type="search" @click="goSearch" />
    </div>
    <div class="columnList">
        <scroller ref="myscroller" class="scroll" :on-infinite="infinite">
            <div class="musicItem-box">
              <div class="musicItem" v-for="(item,index) in singnav" :key="index">
                  <router-link :to="'/ExclusiveColumnList?id='+item.id">
                      <div class="musicImg">
                          <!-- 新 -->
                          <div class="newText" v-if="index<2">新</div>
                          <img :src="item.imgUrl" />
                          <!-- 听 -->
                          <div class="listenBox">
                              <div>{{item.playCount || 0}}播放</div>
                          </div>
                      </div>
                      <div class="musicWord">{{item.title || '好先生与皓先生'}}</div>
                      <div class="lowSongs">{{item.desc}}</div>
                  </router-link>
                  <!-- <router-link v-if="item.tag" tag="div" class="lowSongs" :to="'/PopSlowSongs?id='+item.id">{{item.desc}}</router-link> -->
              </div>
            </div>
        </scroller>
        <!-- <div class="end" v-if="singnavisEnd">没有更多了~</div> -->
    </div>
</div>
</template>

<script>
import controller from "@/components/controllers/controllers";
export default {
    name: "column",
    data() {
        return {
            singnav: [],
            page: 1,
            pageSize: 10,
            isEnd: false,
            search: ""
        };
    },
    mounted() {
        this.categoryListover()
        window.addEventListener('mousewheel',this.handleScroll);
    },
    destroyed(){
      window.removeEventListener('mousewheel',this.handleScroll)
    },
    methods: {
      handleScroll(e){
        let that = this  //此this指向的是vue
        console.log(e.wheelDelta)
        if (e.wheelDelta < 0) {
            that.$refs.myscroller && (that.$refs.myscroller.scrollBy(0, 50, true));
        } else {
          that.$refs.myscroller && (that.$refs.myscroller.scrollBy(0, -50, true));
        }
      },
      goSearch(){
        this.$router.push({
          path:'/columnSearch'
        })
      },
        categoryListover(idx=null) {
            let _self = this
            controller.categoryList({
                keyword: "",
                page: this.page,
                pageSize: this.pageSize,
                isIndex: idx,
            }).then(res => {
              console.log(res)
                if (res.baseData.list.length > 0) {
                    _self.singnav = _self.singnav.concat(res.baseData.list)
                    _self.isEnd = res.baseData.lastPage
                }
            }).catch(res => {

            })
        },
        // 上拉加载
        infinite(done) {
          setTimeout(() => {
            if (this.isEnd) {
                this.$refs.myscroller.finishInfinite(true); //这个方法是不让它加载了，显示“没有更多数据”，要不然会一直转圈圈
            } else {
              this.page += 1
              this.categoryListover()
              done(); //进行下一次加载操作
            }
          }, 1500);
        },
    }
};
</script>

<style lang="scss" scoped>
.column {
    // width: 750px;
    min-width: 640px;
    max-width: 960px;
    margin: 0 auto;

    .swarchBox {
        // width: 702px;
        width: 93.6%;
        height: 64px;
        background-color: #f6f6fa;
        color: #a8acbb;
        font-size: 28px;
        border-radius: 32px;
        margin: 0 auto;
        margin-top: 24px;
        overflow: hidden;
        position: relative;

        img {
            position: absolute;
            left: 24px;
            top: 20px;
            width: 25px;
            height: 25px;
        }

        input {
            width: 100%;
            height: 100%;
            background-color: #f6f6fa;
            padding-left: 68px;
            box-sizing: border-box;
            border: none;
						outline:0;
        }
    }

    /* 歌曲列表 */
    .columnList {
        padding: 0 30px ;
        margin-top: 32px;
        box-sizing: border-box;
        height: calc(100vh - 120px);

        .scroll {
            position: static;
            /deep/ ._v-content{
                padding-bottom: 100px;
            }

            .musicItem-box{
              display: flex;
              justify-content: space-between;
              flex-wrap: wrap;
            }

            /* 音乐 */
            .musicItem {
                width: 48%;
                position: relative;
                margin-bottom: 26px;
                background-color: #F2F2F2;
                border-radius: 8px;

                .musicImg {
                    width: 100%;
                    // height: 330px;
                    border-radius: 8px;
                    overflow: hidden;
                    position: relative;

                    img {
                        width: 100%;
                        height: 100%;
                        background: #333;
                    }

                    .newText {
                        position: absolute;
                        top: 0;
                        left: 0;
                        width: 71px;
                        height: 71px;
                        color: #fff;
                        font-size: 28px;
                        padding-left: 15px;
                        padding-top: 15px;
                        box-sizing: border-box;
                        background-color: #e66d4d;
                        border-radius: 0 0 85% 0;
                    }

                    .listenBox {
                        width: 100%;
                        height: 48px;
                        position: absolute;
                        bottom: 16px;
                        left: 0;
                        padding: 0 16px;
                        box-sizing: border-box;
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        font-size: 20px;
                        color: #fff;

                        .listenPic {
                            width: 48px;
                            height: 48px;
                            border-radius: 50%;
                            font-size: 25px;
                            display: flex;
                            justify-content: center;
                            align-items: center;
                            background-color: #fff;
                            color: rgb(99, 139, 101);
                        }
                    }
                }

                .musicWord {
                    width: 100%;
                    padding-left: 10px;
                    margin-top: 10px;
                    box-sizing: border-box;
                    font-size: 32px;
                    font-weight: 500;
                    color: #323232;
                }

                .lowSongs {
                    width: 100%;
                    max-height: 80px;
                    line-height: 40px;
                    border-radius: 4px;
                    padding-left: 10px;
                    box-sizing: border-box;
                    margin: 10rpx 0;
                    font-size: 26px;
                    font-weight: 500;
                    color: #A8ACBB;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    /* ! autoprefixer: off */
											-webkit-box-orient: vertical;
										/* autoprefixer: on */
                }
            }

            .musicItem:nth-child(2n-1) {
                // margin-right: 26px;
                margin-right: 4%;
            }
        }
    }
}
</style>
